﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_SMS_SaveMobileMsgToBuffer]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_SMS_SaveMobileMsgToBuffer];
GO
CREATE PROCEDURE [dbo].[sproc_SMS_SaveMobileMsgToBuffer]
    @Sender         nvarchar(50),
    @RecipientMobileNo                nvarchar(255),
    @Content             nvarchar(255),
    @Sendtime             datetime,
    @RepeatTimes        int,
    @RepeatPeriod        int 
            
/*

============================================================
功能:    手机短消息发送
参数:
    @Sender                     nvarchar(50)        :    发送者用户名
    @RecipientMobileNo  nvarchar(20)        :    接收者手机号码
    @Content                   nvarchar(255)        :    信息内容
    @sendtime                 datetime             ;    发送时间
             @RepeatTimes            int                ;    重复发送分钟数
    @RepeatPeriod            int                ;    重复间隔时间(以分钟为单位)
============================================================

*/

AS
SET NOCOUNT ON
DECLARE @MobileNo nvarchar(30)
WHILE LEN(@RecipientMobileNo)>0 
BEGIN
    --如果不是最后一次
    IF(charindex(',',@RecipientMobileNo)>0)
    BEGIN
    --截取逗号前数据
    SET @MobileNo = substring(@RecipientMobileNo,1,charindex(',',@RecipientMobileNo)-1)
    --剪切字符串
    SET @RecipientMobileNo = substring(@RecipientMobileNo,charindex(',',@RecipientMobileNo)+1,LEN(@RecipientMobileNo))    
    INSERT INTO 
        UDS_SMS_MobileMsgSendBuffer (Sender,RecipientMobileNo,Content,SendTime,RepeatTimes,RepeatPeriod) 
    VALUES
        (@Sender,@MobileNo,@Content,@Sendtime,@RepeatTimes,@RepeatPeriod)
    print @MobileNo
    --print @Mobile
    END 
    ELSE
    BEGIN
        --PRINT @Receivers
        --PRINT @MobileNo
    INSERT INTO 
        UDS_SMS_MobileMsgSendBuffer (Sender,RecipientMobileNo,Content,SendTime,RepeatTimes,RepeatPeriod) 
    VALUES
        (@Sender,@RecipientMobileNo,@Content,@Sendtime,@RepeatTimes,@RepeatPeriod)
    BREAK
    END


END

SET NOCOUNT OFF